package com.github.gin.springboot.config;

import com.github.gin.springboot.cxf.UserServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * Created by GinPonson on 2016/12/18.
 */
@Configuration
@ConditionalOnClass(CXFServlet.class)
public class CXFConfiguration {

    @Bean
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public Object userService() {
        return new UserServiceImpl();
    }

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), userService());
        endpoint.publish("/user");
        return endpoint;
    }

    /*@Bean
    public Object authorService() {
        return new AuthorServiceImpl();
    }
    @Bean
    public Endpoint authorEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), authorService());
        endpoint.publish("/author");
        return endpoint;
    }*/

}
